/**
 * Created by IntelliJ IDEA.
 * User: Alex
 * Date: 4/28/11
 * Time: 1:54 PM
 * To change this template use File | Settings | File Templates.
 */

/*
A function that creates  ajax call to the twitter search api and returns 5 results
uses "fast" polling with an interval of 30 seconds when a response is returned JSON
data is parsed and inserted as table rows to the twitter feed table after the previous
results have been removed
 */
function queryTwitter(query){
    $.ajax({
        dataType:'json',
        url:"http://search.twitter.com/search.json?q="+query+"&rpp=5&callback=?",
        success:function(results){
            $(".twitterFeed .tweet").remove();
            $.each(
                results.results,
                function(index, tweet){
                    var ele="<table><tr class='tweet'><td class='author'><strong>"+
                            tweet.from_user+
                            "</strong></td><td class='body'>"+
                            tweet.text+"</td></tr></table>";
                    $(".twitterFeed").append(ele);
                }
            );
            setTimeout(queryTwitter,30000,[query]);

        }
    });
}


function setUpTwitterFeed(title){
    queryTwitter(title);
}
